//
//  UIView+Frame.m
//  PSCanvasDemo
//
//  Created by Passing on 2017/8/6.
//  Copyright © 2017年 passing. All rights reserved.
//

#import "UIView+Frame.h"

@implementation UIView (Frame)

- (CGFloat)top
{
    return self.frame.origin.y;
}

- (void)setTop:(CGFloat)y
{
    CGRect frame = self.frame;
    frame.origin.y = y;
    self.frame = frame;
}

- (CGFloat)right
{
    return self.frame.origin.x + self.frame.size.width;
}

- (void)setRight:(CGFloat)right
{
    CGRect frame = self.frame;
    frame.origin.x = right - self.frame.size.width;
    self.frame = frame;
}

- (CGFloat)bottom
{
    return self.frame.origin.y + self.frame.size.height;
}

- (void)setBottom:(CGFloat)bottom
{
    CGRect frame = self.frame;
    frame.origin.y = bottom - self.frame.size.height;
    self.frame = frame;
}

- (CGFloat)left
{
    return self.frame.origin.x;
}

- (void)setLeft:(CGFloat)x
{
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}

-(void)setCenterY:(CGFloat)centerY
{
    CGPoint center = self.center;
    center.y = centerY;
    self.center = center;
}
- (CGFloat)centerY
{
    return self.center.y;
}


- (CGFloat)width
{
    return self.frame.size.width;
}

- (CGFloat)y
{
    return self.frame.origin.y;
}

- (void)setWidth:(CGFloat)width
{
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}

- (CGFloat)height
{
    return self.frame.size.height;
}

- (void)setHeight:(CGFloat)height
{
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}





- (void)setBorderWidth:(CGFloat)with
{
    self.layer.borderWidth = with;
}

- (CGFloat)borderWidth
{
    return self.layer.borderWidth;
}

- (void)setBorderColor:(UIColor *)color
{
    self.layer.borderColor = color.CGColor;
}

- (UIColor *)borderColor
{
    return [UIColor colorWithCGColor:self.layer.borderColor];
}

- (CGFloat)x
{
    return self.frame.origin.x;
}


- (CGPoint)origin
{
    return self.frame.origin;
}

- (CGSize)size
{
    return self.frame.size;
}

- (void)setX:(CGFloat)x
{
    self.frame = (CGRect){
        .origin = {.x = x, .y = self.y},
        .size   = {.width = self.width, .height = self.height}
    };
}

- (void)setY:(CGFloat)y
{
    self.frame = (CGRect){
        .origin = {.x = self.x, .y = y},
        .size   = {.width = self.width, .height = self.height}
    };
}


- (void)setOrigin:(CGPoint)origin
{
    self.frame = (CGRect){
        .origin = {.x = origin.x, .y = origin.y},
        .size   = {.width = self.width, .height = self.height}
    };
}

- (void)setSize:(CGSize)size
{
    self.frame = (CGRect){
        .origin = {.x = self.x, .y = self.y},
        .size   = {.width = size.width, .height = size.height}
    };
}


-(void)setCenterX:(CGFloat)centerX
{
    CGPoint center = self.center;
    center.x = centerX;
    self.center = center;
}

-(CGFloat)centerX
{
    return self.center.x;
}

@end
